//
//  BRThemeManage.m
//  BrezzeSaaS
//
//  Created by IOS on 2021/12/9.
//  Copyright © 2021 Brezze GWG. All rights reserved.
//

#import "BRThemeManage.h"

@implementation BRThemeManage

+ (BOOL)isThemeDark {
    
    if ([[NSUserDefaults standardUserDefaults] objectForKey:kThemeDarkKey]) {
        return [[NSUserDefaults standardUserDefaults] boolForKey:kThemeDarkKey];
    }
    
    return NO;
}

+ (void)setTemeDark:(BOOL)isDark {
    [[NSUserDefaults standardUserDefaults] setBool:isDark forKey:kThemeDarkKey];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

+ (BOOL)isMapDark {
    
    return [[self class] isHasDark];
}

+ (BOOL)isHasDark {
    if ([[[self class] themeName] isEqualToString:QDThemeIdentifierDark]) {
        return YES;;
    }
    
    return NO;
}

+ (UIImage *)br_resizableImg:(NSString *)str edg:(UIEdgeInsets)edg {
    UIImage *bubble = UIImageMake(str);
    //
    return [bubble resizableImageWithCapInsets:edg resizingMode:UIImageResizingModeStretch];
}

+ (UIImage *)br_graduallyImg{
   
    
    CGRect frame = CGRectMake(0, 0, 147, 147);
    UIView *view = [[UIView alloc] initWithFrame:frame];
    
    CAGradientLayer *gl = [CAGradientLayer layer];
    gl.frame = frame;
    gl.startPoint = CGPointMake(0.50, 0.00);
    gl.endPoint = CGPointMake(0.50, 1.00);
    gl.colors = @[
    (__bridge id)[UIColor colorWithRed:78/255.0 green:196/255.0 blue:255/255.0 alpha:1.00].CGColor,
    (__bridge id)[UIColor colorWithRed:47/255.0 green:153/255.0 blue:255/255.0 alpha:1.00].CGColor,
    ];
    gl.locations = @[@(0),@(1.f)];
    [view.layer addSublayer:gl];
    
    // 绘制圆角 需设置的圆角 使用"|"来组合
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:frame byRoundingCorners:
    UIRectCornerTopLeft | UIRectCornerTopRight| UIRectCornerBottomLeft| UIRectCornerBottomRight cornerRadii:CGSizeMake(33, 33)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc]init];

    // 设置大小vi
    maskLayer.frame = frame;
    // 设置图形样子
    maskLayer.path = maskPath.CGPath;
    view.layer.mask = maskLayer;
    
    UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, [UIScreen mainScreen].scale);
    
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGRect rect = frame;
    CGContextAddEllipseInRect(ctx, rect);
    CGContextClip(ctx);
    
//    [kDefaultImg drawInRect:rect];
    UIImage *circleImage = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    
    return circleImage;
}

+ (void)br_statusBarStyle {
    
    if ([[[self class] themeName] isEqualToString:QDThemeIdentifierDark]) {
        
        [[self class] br_isDarkStatusBar:NO];
        return;
    }
    [[self class] br_isDarkStatusBar:YES];
    
}

+ (void)br_isDarkStatusBar:(BOOL)isDark {
    
    if (!isDark) {
        // 白色
        [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
        return;
    }
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDarkContent;
}

+ (NSString *)themeName {
    return QDThemeManager.currentTheme.themeName;
}

+ (NSString *)br_walletCardBGName {
    
    if ([QDThemeManager.currentTheme.themeName isEqualToString:QDThemeIdentifierGrass]) {
        return @"wallet_cardBG2";
    }
    if ([QDThemeManager.currentTheme.themeName isEqualToString:QDThemeIdentifierDark]) {
        return @"wallet_cardBG3";
    }
    if ([QDThemeManager.currentTheme.themeName isEqualToString:QDThemeIdentifierBST]) {
        return @"wallet_cardBG4";
    }
    if ([QDThemeManager.currentTheme.themeName isEqualToString:QDThemeIdentifierTanzania]) {
        return @"wallet_cardBG5";
    }
    if ([QDThemeManager.currentTheme.themeName isEqualToString:QDThemeIdentifierIBoom]) {
        return @"wallet_cardBG6";
    }
    return @"wallet_cardBG";
}

+ (NSArray *)br_walletBGName {
    
    return @[UIColorMake(0, 185, 255),UIColorMake(60, 144, 255)];
}

+ (NSArray *)br_payStatusSuccBGColors {
    if ([QDThemeManager.currentTheme.themeName isEqualToString:QDThemeIdentifierGrass]) {
        return @[UIColorMake(44, 185, 128),UIColorMake(255, 255, 255),UIColorMake(255, 255, 255)];
    }
    
    if ([QDThemeManager.currentTheme.themeName isEqualToString:QDThemeIdentifierDark]) {
        return @[UIColorDarkBlack1,UIColorDarkBlack1,UIColorDarkBlack1];
    }
    //F2F5FA = 242, 245, 250
    if ([QDThemeManager.currentTheme.themeName isEqualToString:QDThemeIdentifierBST]) {
        return @[UIColorMake(242, 245, 250),UIColorMake(242, 245, 250),UIColorMake(242, 245, 250)];
    }
    if ([QDThemeManager.currentTheme.themeName isEqualToString:QDThemeIdentifierTanzania]) {
        return @[UIColorMake(242, 245, 250),UIColorMake(242, 245, 250),UIColorMake(242, 245, 250)];
    }
    if ([QDThemeManager.currentTheme.themeName isEqualToString:QDThemeIdentifierIBoom]) {
        return @[UIColorMakeWithHex(@"#F2F5FA"),UIColorMakeWithHex(@"#F2F5FA"),UIColorMakeWithHex(@"#F2F5FA")];
    }
    
    return @[[UIColor colorWithRed:60/255.0 green:144/255.0 blue:255/255.0 alpha:1.0],[UIColor colorWithRed:0/255.0 green:185/255.0 blue:255/255.0 alpha:1.0],[UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0]];
}

+ (NSArray *)br_payStatusLineBGColors {
    
    if ([QDThemeManager.currentTheme.themeName isEqualToString:QDThemeIdentifierDark]) {
        return @[UIColorDarkBlack3,UIColorDarkBlack3];
    }
    
    return @[[UIColor colorWithRed:245/255.0 green:245/255.0 blue:247/255.0 alpha:1.0],[UIColor colorWithRed:210/255.0 green:216/255.0 blue:226/255.0 alpha:1.0]];
}

+ (NSArray *)br_payStatusFailBGColors {
//    if ([QDThemeManager.currentTheme.themeName isEqualToString:QDThemeIdentifierGrass]) {
//        return @[UIColorMakeWithHex(@"#FD5849"),UIColorMakeWithHex(@"#8FE0FF"),[UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0]];
//    }
    if ([QDThemeManager.currentTheme.themeName isEqualToString:QDThemeIdentifierDark]) {
        return @[UIColorDarkBlack1,UIColorDarkBlack1];
    }
    
    //F2F5FA = 242, 245, 250
    if ([QDThemeManager.currentTheme.themeName isEqualToString:QDThemeIdentifierBST]) {
        return @[UIColorMake(242, 245, 250),UIColorMake(242, 245, 250),UIColorMake(242, 245, 250)];
    }
    if ([QDThemeManager.currentTheme.themeName isEqualToString:QDThemeIdentifierTanzania]) {
        return @[UIColorMake(242, 245, 250),UIColorMake(242, 245, 250),UIColorMake(242, 245, 250)];
    }
    if ([QDThemeManager.currentTheme.themeName isEqualToString:QDThemeIdentifierIBoom]) {
        return @[UIColorMakeWithHex(@"#F2F5FA"),UIColorMakeWithHex(@"#F2F5FA"),UIColorMakeWithHex(@"#F2F5FA")];
    }
    
    return @[[UIColor colorWithRed:253/255.0 green:88/255.0 blue:73/255.0 alpha:1.0],[UIColor colorWithRed:143/255.0 green:224/255.0 blue:255/255.0 alpha:1.0],[UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0]];
}

+ (NSArray *)br_payStatusFailBGColorsLocations {
    return @[@(0), @(0.4f), @(1.0f)];
}

+ (NSArray *)br_payStatusSuccBGColorsLocations {
    if ([QDThemeManager.currentTheme.themeName isEqualToString:QDThemeIdentifierGrass]) {
        return @[@(0),@(0.8f), @(1.0f)];
    }
    return @[@(0), @(0.2f), @(1.0f)];
}

+ (NSArray *)br_refunedStatusLineBGColors {
    
    if ([QDThemeManager.currentTheme.themeName isEqualToString:QDThemeIdentifierDark]) {
        return @[UIColorDarkBlack1,UIColorDarkBlack1];
    }
    
    return @[[UIColor colorWithRed:0/255.0 green:185/255.0 blue:255/255.0 alpha:1.0],[UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0]];
}

+ (NSArray *)br_2gadientColors {
    
    NSLog(@"IM here == %@",QDThemeManager.currentTheme.themeName);
    NSString *themeName = QDThemeManager.currentTheme.themeName;
    if ([themeName isEqualToString:QDThemeIdentifierGrass]) {
        return @[UIColorMakeWithRGBA(44, 185, 128, 1),UIColorMakeWithRGBA(35, 153, 103, 1)];
        
    }
    
    if ([themeName isEqualToString:QDThemeIdentifierDark]) {
        return @[UIColorMakeWithRGBA(79, 128, 255, 1),UIColorMakeWithRGBA(79, 128, 255, 1)];
    }
    // #FF5500 = 255, 85, 0,  #FA9E35 = 250,158, 53
    if ([themeName isEqualToString:QDThemeIdentifierBST]) {
        return @[UIColorMakeWithRGBA(255, 85, 0, 1),UIColorMakeWithRGBA(250, 158, 53, 1)];
    }
    
    // #122C6F = 18,44,11
    if ([themeName isEqualToString:QDThemeIdentifierTanzania]) {
        return @[UIColorMakeWithRGBA(18,44,111, 1),UIColorMakeWithRGBA(18,44,111, 1)];
    }
    if ([themeName isEqualToString:QDThemeIdentifierIBoom]) {
        return @[UIColorMakeWithHex(@"#802CB6"),UIColorMakeWithHex(@"#802CB6") ];
    }
    
    return @[kColorMain,kColorMain];
}
+ (NSArray *)br_2gadientColors2 {
    NSString *themeName = QDThemeManager.currentTheme.themeName;
    if ([themeName isEqualToString:QDThemeIdentifierGrass]) {
        return @[UIColorMakeWithRGBA(44, 185, 128, 1),UIColorMakeWithRGBA(35, 153, 103, 1)];
    }
    
    if ([themeName isEqualToString:QDThemeIdentifierDark]) {
        return @[UIColorMakeWithRGBA(17, 17, 17, 1),UIColorMakeWithRGBA(17, 17, 17, 1)];
    }
    
    // #FF5500 = 255, 85, 0,  #FA9E35 = 250,158, 53
    if ([themeName isEqualToString:QDThemeIdentifierBST]) {
        return @[UIColorMakeWithRGBA(255, 85, 0, 1),UIColorMakeWithRGBA(250, 158, 53, 1)];
    }
    if ([themeName isEqualToString:QDThemeIdentifierTanzania]) {
        return @[UIColorMakeWithRGBA(18,44,111, 1),UIColorMakeWithRGBA(18,44,111, 1)];
    }
    if ([themeName isEqualToString:QDThemeIdentifierIBoom]) {
        return @[UIColorMakeWithHex(@"#802CB6"),UIColorMakeWithHex(@"#802CB6") ];
    }
    
    return @[UIColorMakeWithRGBA(0, 185, 255, 1),UIColorMakeWithRGBA(60, 144, 255, 1)];
}
+ (NSArray *)br_2gadientColors3 {
    NSString *themeName = QDThemeManager.currentTheme.themeName;
    if ([themeName isEqualToString:QDThemeIdentifierGrass]) {
        return @[UIColorMakeWithRGBA(97, 197, 156, 1),UIColorMakeWithRGBA(37, 160, 108, 1)];
    }
    
    if ([themeName isEqualToString:QDThemeIdentifierDark]) {
        return @[UIColorMakeWithRGBA(79, 128, 255, 1),UIColorMakeWithRGBA(79, 128, 255, 1)];
    }
    
    // #FE914D = 254, 145, 77,  #FB8E29 = 251, 142, 41
    if ([themeName isEqualToString:QDThemeIdentifierBST]) {
        return @[UIColorMakeWithRGBA(254, 145, 77, 1),UIColorMakeWithRGBA(251, 142, 41, 1)];
    }
    // 6695ED = 102, 149, 237
    if ([themeName isEqualToString:QDThemeIdentifierTanzania]) {
        return @[UIColorMakeWithRGBA(102, 149, 237, 1),UIColorMakeWithRGBA(102, 149, 237, 1)];
    }
    if ([themeName isEqualToString:QDThemeIdentifierIBoom]) {
        return @[UIColorMakeWithHex(@"#A163C9"),UIColorMakeWithHex(@"#802CB6") ];
    }
    
    return @[UIColorMakeWithRGBA(78, 196, 255, 1),UIColorMakeWithRGBA(47, 153, 255, 1)];
}
+ (NSArray *)br_2gadientColors4 {
    NSString *themeName = QDThemeManager.currentTheme.themeName;
    if ([themeName isEqualToString:QDThemeIdentifierGrass]) {
        return @[UIColorMakeWithRGBA(97, 197, 156, 1),UIColorMakeWithRGBA(37, 160, 108, 1)];
    }
    
    return @[UIColorMakeWithRGBA(0, 185, 255, 1),UIColorMakeWithRGBA(185, 235, 255, 1)];
}

+ (UIColor *)br_05AlphaColor {
    if ([BRThemeManage isHasDark]) {
        return UIColorMakeWithRGBA(255, 255, 255, 0.5);
    }
    return UIColorMakeWithRGBA(38, 38, 38, 0.5);
}

+ (NSArray *)br_homeMapShadowColors {
    if ([BRThemeManage isHasDark]) {
        return @[UIColorMakeWithRGBA(28, 28, 30, 0),UIColorMakeWithRGBA(28, 28, 30,1)];
    }
    return @[UIColorMakeWithRGBA(236,236,238, 0),UIColorMakeWithRGBA(236,236,238,1)];
}

+ (NSString *)br_mapStylePatchWithJsonFile {
    
//    if ([[self class] isHasDark]) {
//        return [[self class] br_stringWithFile:@"bodMapDark" type:@"json"];
//    }
//     
//    return [[self class] br_stringWithFile:@"bodMapDefault" type:@"json"];
    return [[self class] br_stringWithFile:@"GrayMap" type:@"json"];;
}

+ (NSString *)br_stringWithFile:(NSString *)resource type:(NSString *)fileType {
    NSError *error=nil;
    // 通过指定的路径读取文本内容
    NSString *str = [NSString stringWithContentsOfFile:[[self class] br_patchStr:resource type:fileType] encoding:NSUTF8StringEncoding error:&error];
     
//    NSLog(@"srt=%@" ,str);
    if (error) {
        NSLog(@"获取文本错误");
        return @"";
    }
    
    return str;
}

+ (NSString *)br_patchStr:(NSString *)resource type:(NSString *)fileType {
    return [[NSBundle mainBundle] pathForResource:resource ofType:fileType];
}

+ (void)br_changeDeleteIcon:(id)tField {
    
}

@end
